*12-09-24_loop_mi_robustness_h10dm.do


clear
macro drop _all

global filetree /Users/Allan/Dropbox/!!Papers/Liberal Peace/12-02-21_ISQ_commentary/DOR_ISQ_2013_Replication/M_Rep

cd "$filetree"
use "midata"

mi xtset, clear

**check that logit runs with midyears*
sort ccode1 ccode2 year
global controls lncprt mjpw contigl lndist numstate

gen specification="NA"
gen specnumber=.
gen n=.
gen h10dmCoefficient=.
gen h10dmSE=.
gen CIElCoefficient=.
gen CIElSE=.
gen h10dmpvalues=.
gen CIElpvalues=.

gen bdm=.
replace bdm=1 if dml>6 & dml<11
replace bdm=0 if dml<=6 & dml>=-10 

mi passive: generate bdmCIElc= bdm*CIElc

gen h10dm=.
replace h10dm=1 if dml>9 & dml<11
replace h10dm=0 if dml<=9 & dml>=-10 

mi passive: generate h10dmCIElc= h10dm*CIElc

**Code just to see if things are running
mi estimate, dots: logit fmidonsl lnlifedeerl h10dm $controls fmidyears*, cl(dyadid) 
logit midonsl _1_lnlifedeerl h10dm $controls	 midyears*, cl(dyadid) 
logit midonsl _2_lnlifedeerl h10dm $controls	 midyears*, cl(dyadid) 
logit fmidonsl _3_lnlifedeerl h10dm $controls	 fmidyears*, cl(dyadid) nolog
****

sort ccode1 ccode2 year

local j=0

**M2 m.i. with 4 dependent variables x interaction = 8 models
local j=`j'+1
local spec`j' "M''"
local covars`j' "midonsl CIEl  h10dm 					   $controls midyears*"


local j=`j'+1
local spec`j' "OM''"
local covars`j' "midongl CIEl  h10dm 					   $controls midyears*"


local j=`j'+1
local spec`j' "FM''"
local covars`j' "fmidonsl CIEl  h10dm 					   $controls fmidyears*"


local j=`j'+1
local spec`j' "FOM''"
local covars`j' "fmidongl CIEl  h10dm 					   $controls fmidyears*"

local j=`j'+1
local spec`j' "IM''"
local covars`j' "midonsl CIElc  h10dm h10dmCIElc 					   $controls midyears*"


local j=`j'+1
local spec`j' "OIM''"
local covars`j' "midongl CIElc  h10dm 	 h10dmCIElc 				   $controls midyears*"


local j=`j'+1
local spec`j' "FIM''"
local covars`j' "fmidonsl CIElc  h10dm 		 h10dmCIElc 			   $controls fmidyears*"


local j=`j'+1
local spec`j' "FOIM''"
local covars`j' "fmidongl CIElc  h10dm  	h10dmCIElc 				   $controls fmidyears*"



**M2 m.i. with DemocracyHigh with 4 dependent variables x interaction = 8 models


**M2 with 4 dependent variables x interaction = 8 models
local j=`j'+1
local spec`j' "DM''"
local covars`j' "midonsl CIEl  h10dm  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j' "ODM''"
local covars`j' "midongl CIEl  h10dm  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j' "FDM''"
local covars`j' "fmidonsl CIEl  h10dm  dmh 					   $controls fmidyears*"


local j=`j'+1
local spec`j' "FODM''"
local covars`j'  "fmidongl CIEl  h10dm  dmh					   $controls fmidyears*"


local j=`j'+1
local spec`j'  "IDM''"
local covars`j'  "midonsl CIElc  h10dm h10dmCIElc 	 dmh 				   $controls midyears*"


local j=`j'+1
local spec`j'  "OIDM''"
local covars`j'  "midongl CIElc  h10dm 	 h10dmCIElc 	 dmh 			   $controls midyears*"


local j=`j'+1
local spec`j'  "FIDM''"
local covars`j'  "fmidonsl CIElc  h10dm 		 h10dmCIElc 	 dmh 		   $controls fmidyears*"


local j=`j'+1
local spec`j'  "FOIDM''"
local covars`j' "fmidongl CIElc  h10dm  	h10dmCIElc 	 dmh 			   $controls fmidyears*"




****With other measures of life insurance expenditures


**M2 m.i. with 4 dependent variables x interaction = 8 models
local j=`j'+1
local spec`j' "L''"
local covars`j' "midonsl lnlifepenl  h10dm 					   $controls midyears*"


local j=`j'+1
local spec`j' "OL''"
local covars`j' "midongl lnlifepenl  h10dm 					   $controls midyears*"


local j=`j'+1
local spec`j' "FL''"
local covars`j' "fmidonsl lnlifepenl  h10dm 					   $controls fmidyears*"


local j=`j'+1
local spec`j' "FOL''"
local covars`j' "fmidongl lnlifepenl  h10dm 					   $controls fmidyears*"

local j=`j'+1
local spec`j' "IL''"
local covars`j' "midonsl CIElc  h10dm h10dmCIElc 					   $controls midyears*"


local j=`j'+1
local spec`j' "OIL''"
local covars`j' "midongl CIElc  h10dm 	 h10dmCIElc 				   $controls midyears*"


local j=`j'+1
local spec`j' "FIL''"
local covars`j' "fmidonsl CIElc  h10dm 		 h10dmCIElc 			   $controls fmidyears*"


local j=`j'+1
local spec`j' "FOIL''"
local covars`j' "fmidongl CIElc  h10dm  	h10dmCIElc 				   $controls fmidyears*"



**M2 m.i. with DemocracyHigh with 4 dependent variables x interaction = 8 models

local j=`j'+1
local spec`j' "DL''"
local covars`j' "midonsl lnlifepenl  h10dm  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j' "ODL''"
local covars`j' "midongl lnlifepenl  h10dm  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j' "FDL''"
local covars`j' "fmidonsl lnlifepenl  h10dm  dmh 					   $controls fmidyears*"


local j=`j'+1
local spec`j' "FODL''"
local covars`j'  "fmidongl lnlifepenl  h10dm  dmh					   $controls fmidyears*"


local j=`j'+1
local spec`j'  "IDL''"
local covars`j'  "midonsl CIElc  h10dm h10dmCIElc 	 dmh 				   $controls midyears*"


local j=`j'+1
local spec`j'  "OIDL''"
local covars`j'  "midongl CIElc  h10dm 	 h10dmCIElc 	 dmh 			   $controls midyears*"


local j=`j'+1
local spec`j'  "FIDL''"
local covars`j'  "fmidonsl CIElc  h10dm 		 h10dmCIElc 	 dmh 		   $controls fmidyears*"


local j=`j'+1
local spec`j'  "FOIDL''"
local covars`j' "fmidongl CIElc  h10dm  	h10dmCIElc 	 dmh 			   $controls fmidyears*"


sort ccode1 ccode2 year

**Estimating Models, Saving Values
forvalues k=1(1)`j' {
replace specification="`spec`k''" if _n==`k'
mi estimate, dots: logit `covars`k'', cl(dyadid) nolog
mat A=e(b_mi)
mat V=e(V_mi)
replace n= e(N)   if _n==`k'
replace specnumber=`k' if _n==`k'
replace h10dmCoefficient=A[1,2] if _n==`k'
replace h10dmSE=(V[2,2])^(1/2) if _n==`k'
replace CIElCoefficient=A[1,1] if _n==`k'
replace CIElSE=(V[1,1])^(1/2) if _n==`k'
}


order specification specnumber n h10dmCoefficient h10dmSE h10dmpvalues CIElCoefficient CIElSE CIElpvalues
replace h10dmpvalues=2*normal(-abs(h10dmCoefficient/h10dmSE))
replace CIElpvalues=2*normal(-abs(CIElCoefficient/CIElSE))
keep specification specnumber n h10dmCoefficient h10dmSE h10dmpvalues CIElCoefficient CIElSE CIElpvalues
drop if specnumber==.

saveold "robustnessMh10dm.dta", replace




